<?php
// $Id$

include_once('BaseModel.class.php');

class FoldersModel extends BaseModel
{
    function collect($offset=null,$limit=null,$search=array(),$by='1',$sort='',$u_id='',$u_prv='')
	{
		$where = ($search) ? "WHERE LOWER({$search['searchfield']}) LIKE '%{$search['searchtext']}%'" : "WHERE 1";

		if (is_null($offset)) {
            
                  if ($u_prv="ADMINISTOR" OR $u_prv="SYSTEM ADMINISTRATOR"){
	            $query = "SELECT COUNT(*) FROM folders $where AND active=1";
                  }else{
	            $query = "SELECT COUNT(*) FROM folders $where AND auth_id ='$u_id' AND active=1";
                  }
		} else {
                  if ($u_prv="ADMINISTRATOR" OR $u_prv="SYSTEM ADMINISTRATOR"){
                    $query = "SELECT * FROM folders $where AND active=1 ORDER BY $by $sort LIMIT $offset,$limit";
                  }else{
                    $query = "SELECT * FROM folders $where AND auth_id='$u_id' AND active=1 ORDER BY $by $sort LIMIT $offset,$limit";
                  }
		}
		return $this->query($query, true);
    }

    function detail ($id)
    {
        $query = "SELECT * FROM folders WHERE id='$id'";
        return $this->query($query, true);
    }

    /*
     * Add members and return the new member_id
     *
     */
    function ins($detail)
    {
        return $this->insert('folders', $detail);
        return $this->last_insert_id('folders');
    }

    /*
     * Update categories for a particular categories_id
     *
     */
    function edit ($id, $detail)
    {
        return $this->update('folders', $detail, "id = '$id'");
    }

    /*
     * Delete members detail for a particular member_id
     *
     */
    function deactivate ($id)
    {
        $query = "UPDATE folders SET active = '0' WHERE id='$id'";
        return $this->query($query, false);
    }
    function activate ($id)
    {
        $query = "UPDATE folders SET active = '1' WHERE id='$id'";
        return $this->query($query, false);
    }
}

?>
